package com.jt.controller;

import com.jt.service.FileService;
import com.jt.vo.ImageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
public class FileController {
    @Autowired
    private FileService fileService;

    @RequestMapping("/file")
//    MultipartFilespringmvc的顶级借口，用来实现文件上传
    public String file(MultipartFile fileImage) throws IOException {
        String dirPath="E:/updateImage";
//        包装目录
        File dirFile=new File(dirPath);
        if (!dirFile.exists()){
            dirFile.mkdirs();
        }

//        动态获取API
        String fileName= fileImage.getOriginalFilename();
        File file1=new File(dirFile+"/"+fileName);
        fileImage.transferTo(file1);
        return "上传成功";

    }
    /**url:http://localhost:8091/pic/upload?dir=image
     * @param: uploadFile
     * @return: ImageVo
     */


    @RequestMapping("/pic/upload")

    public ImageVO upload(MultipartFile uploadFile){
        return fileService.upload(uploadFile);

    }

}
